{include file="head_2" title="用户添加" /}
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">用户添加</div>
            <div class="layui-card-body" style="padding: 15px;">
                <form id="form" class="layui-form" action="{:url('users/add_submit');}" method="post" style="width:50%;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">账号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="user" value="" lay-verify="required" autocomplete="off" placeholder="请输入账号" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" value="" lay-verify="required" autocomplete="off" placeholder="请输入姓名" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="pwd" value="123456"  lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux"></div>
                            </div>
                        </div>
                    
                    <div class="layui-form-item">
                            <label class="layui-form-label">关联角色：</label>
                            <div class="layui-input-block">
                                {foreach $rules as $v } 
                                    <input type="checkbox" name="rules[]" title="{$v.name}" value='{$v.id}' >
                                {/foreach} 
                            </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">编辑类型:</label>
                        <div class="layui-input-block">
                            <div class="from_table">
                                <table border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td width="530">
                                            {php}
                                            $icontypes_arr = $s??'' ? expolde(',',$s->icontypes):[];
                                            {/php}
                                            {foreach $modes as $k=>$v }
                                            <fieldset class='layui-elem-field'> <legend>{$v}</legend>
                                                <p style='text-align:right;'><input value='全选' onclick='checkbox("{$k}")' type='button'class='layui-btn layui-btn-mini'> <input value='取消' onclick='checkbox1("{$k}")' type='button' class='layui-btn layui-btn-danger layui-btn-mini'></p>
                                                <div class='layui-field-box'>
                                                    <div class='borders box_{$k}'>
                                                        <blockquote class='layui-elem-quote layui-quote-nm'>
                                                            {foreach $icontypes as $v2 }
                                                            {if $v2['mode'] == $k}
                                                            <input name='icontypes[]'   value='{$v2.id}' type='checkbox'  title='{$v2.name}' {in name="$v2.id" value="$icontypes_arr"}checked{/in}  />
                                                            {/if}
                                                            {/foreach}
                                                        </blockquote>
                                                    </div>
                                                </div>
                                            </fieldset>
                                            {/foreach}
                                    </tr>
                                </table>
                            </div>

                        </div>
                    </div>
                    <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">排序</label>
                                <div class="layui-input-inline">
                                    <input type="number" name="sort" value="100" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">值大靠前</div>
                            </div>
                        </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
                            <button type="button" class="layui-btn layui-btn-primary" onclick="javascript:history.back(-1)">返回</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="{$Think.const.admin_tpl}/layui/layui.js"></script>  
    <script>
        layui.config({
            base: '{$Think.const.admin_tpl}/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate'], function () {
            var $ = layui.$
                    , layer = layui.layer
                    , form = layui.form;
                    
            /* 监听提交 */
            form.on('submit(sub)', function (data) {
                console.log($("#form").serialize());
                $.ajax({
                    url: "/admin/users/add_submit/",
                    type: 'post',
                    data: $("#form").serialize(),
                    dataType: 'json',
                    success: function (data) {
                        // console.log(data);
                        if(data.status==1)
                        {
                            layer.confirm('操作成功！请选择？', {
                                btn: ['继续添加','返回列表'] //按钮
                              }, function(){
                                  location.reload();
                              }, function(){
                                  location.href = '/admin/users/index.html';
                              });
                        }
                        else
                        {
                            layer.msg(data.msg);
                        }
                    },
                    error: function (msg) {
                        alert(" 数据保存失败！" + msg);
                    }
                });
                return false;
            });



        });
        function checkbox(id)
        {
            $(".box_" + id).find("input").each(function (j, n) {
                if (!n.checked)
                {
                    $(this).attr("checked", true);
                    $(".box_" + id).find(".layui-form-checkbox").addClass("layui-form-checked");

                }
            });
        }
        function checkbox1(id)
        {
            $(".box_" + id).find("input").each(function (j, n) {
                console.log('n',n)
                if (n.checked)
                {
                    $(this).attr("checked", false);
                    $(".box_" + id).find(".layui-form-checkbox").removeClass("layui-form-checked");
                }
            });
        }
    </script>
    </body>
</html>